home *** CD-ROM | disk | FTP | other *** search
/ PC Player 2004 May / pc player 2004-05.iso / Demos / FarCry / Data1.cab / _63549FFB7FED4775806F5261820ACF78 < prev    next >
Encoding:
Text File  |  2004-01-06  |  15.2 KB  |  612 lines

  1. --
  2. -- options menu page
  3. --
  4. function FormatName(szName)
  5.     local c = strsub(szName, 1, 1);
  6.     local szResult = strupper(c)..strsub(szName, 2);
  7.  
  8.     return szResult;
  9. end
  10.  
  11.  
  12. UI.PageCampaign=
  13. {    
  14.     GUI=
  15.     {
  16.         StartNewGameTab=
  17.         {
  18.             text = Localize("StartNewGame"),
  19.             skin = UI.skins.TopMenuButton,
  20.             
  21.             greyedcolor = "12, 44, 6, 255",
  22.             
  23.             tabstop = 1,
  24.             
  25.             OnCommand = function(Sender)
  26.                 UI:DeactivateScreen("CampaignLoad");
  27.                 UI:ActivateScreen("CampaignStart");
  28.                 UI:DisableWidget("StartNewGameTab", "Campaign");
  29.                 UI:EnableWidget("LoadSavedGameTab", "Campaign");
  30.             end
  31.         },
  32.  
  33.         LoadSavedGameTab=
  34.         {
  35.             tabstop = 2,
  36.             
  37.             text = Localize("LoadSavedGame"),
  38.             left = 379,
  39.             skin = UI.skins.TopMenuButton,
  40.             
  41.             greyedcolor = "12, 44, 6, 255",
  42.             
  43.             OnCommand = function()
  44.                 UI:DisableWidget("LoadSavedGameTab", "Campaign");
  45.                 UI:EnableWidget("StartNewGameTab", "Campaign");
  46.                 UI:DeactivateScreen("CampaignStart");
  47.                 UI:ActivateScreen("CampaignLoad");
  48.             end
  49.         },
  50.         
  51.         OnInit = function(Sender)
  52.             Game:CreateVariable("ai_autobalance", "0");
  53.         end,        
  54.                     
  55.         OnActivate= function(Sender)
  56.             Sender.StartNewGameTab.OnCommand(Sender.StartNewGameTab);
  57.         end,
  58.     },
  59. };
  60.  
  61. UI.PageCampaignStart=
  62. {    
  63.     GUI=
  64.     {
  65.         Easy=
  66.         {
  67.             skin = UI.skins.CheckBox,
  68.             left = 400, top = 245,
  69.             width = 180, height = 32,
  70.             
  71.             text = Localize("Easy"),
  72.             
  73.             tabstop = 3,
  74.         },
  75.         Medium=
  76.         {
  77.             skin = UI.skins.CheckBox,
  78.             left = 400, top = 285,
  79.             width = 180, height = 32,
  80.             
  81.             text = Localize("Medium"),
  82.             
  83.             tabstop = 4,
  84.         },
  85.         Hard=
  86.         {
  87.             skin = UI.skins.CheckBox,
  88.             left = 400, top = 325,
  89.             width = 180, height = 32,
  90.             
  91.             text = Localize("Hard"),
  92.             
  93.             tabstop = 5,
  94.         },
  95.         
  96.         
  97.         AutoBalanceLabel=
  98.         {
  99.             skin = UI.skins.Label,
  100.  
  101.             left = 580-UI.skins.CheckBox.width-120, top = 365,
  102.             width = 112,
  103.  
  104.             text=Localize("AIAutoBalance"),
  105.         },
  106.  
  107.         AutoBalance=
  108.         {
  109.             skin = UI.skins.CheckBox,
  110.             left = 580-UI.skins.CheckBox.width, top = 365,
  111.             
  112.             tabstop = 6,
  113.             
  114.             OnChanged = function(self)
  115.                 if (self:GetChecked()) then
  116.                     setglobal("ai_autobalance", 1);
  117.                 else
  118.                     setglobal("ai_autobalance", 0);
  119.                 end
  120.             end,
  121.         },        
  122.         -- only available in developer mode
  123.         MapList=
  124.         {
  125.             tabstop = 7,
  126.             skin = UI.skins.ListView,
  127.             
  128.             left = 580, top = 141,
  129.             width = 200, height = 318,
  130.             
  131.             vscrollbar=
  132.             {
  133.                 skin = UI.skins.VScrollBar,
  134.             },
  135.             hscrollbar=
  136.             {
  137.                 skin = UI.skins.HScrollBar,
  138.             },                    
  139.             
  140.             OnCommand = function (Sender)
  141.                 local iLevel = Sender:GetSelection(0);
  142.                 
  143.                 if (iLevel) then
  144.                     local szLevel = Sender:GetItem(iLevel);
  145.                     local szMission = Sender:GetSubItem(iLevel, 1);
  146.                     
  147.                     if (szLevel and strlen(szLevel)) then
  148.                         UI.PageCampaignStart.szLevelName = szLevel.." "..szMission;
  149.                         
  150.                         if (ClientStuff) then
  151.                             UI.YesNoBox(Localize("TerminateCurrentGame"), Localize("TerminateCurrentGameLabel"), UI.PageCampaignStart.ShowSplashScreen);
  152.                         else
  153.                             UI.PageCampaignStart.ShowSplashScreen();
  154.                         end
  155.                     end
  156.                 end
  157.             end
  158.         },
  159.         
  160.         StartGame=
  161.         {
  162.             text=Localize("Start"),
  163.             left = 600,
  164.             skin = UI.skins.BottomMenuButton,
  165.             
  166.             tabstop = 10,
  167.             
  168.             OnCommand=function(Sender)
  169.                 UI.PageCampaignStart.szLevelName = "Research Research";        -- is used by YesNoBox command
  170.  
  171.                 if UI:IsWidgetVisible(UI.PageCampaignStart.GUI.MapList) and UI.PageCampaignStart.GUI.MapList:GetSelection(0) then
  172.                     UI.PageCampaignStart.GUI.MapList.OnCommand(UI.PageCampaignStart.GUI.MapList);
  173.                 else
  174.                     if (ClientStuff) then
  175.                         UI.YesNoBox(Localize("TerminateCurrentGame"), Localize("TerminateCurrentGameLabel"), UI.PageCampaignStart.ShowSplashScreen);
  176.                     else
  177.                         UI.PageCampaignStart.ShowSplashScreen();
  178.                     end
  179.                 end
  180.             end,
  181.         },
  182.                 
  183.         OnActivate = function(Sender)
  184.         
  185.             if (System:IsDevModeEnable()~=1) then
  186.                 UI:HideWidget( UI.PageCampaignStart.GUI.MapList );
  187.             else 
  188.                 UI:ShowWidget( UI.PageCampaignStart.GUI.MapList );
  189.             end
  190.             
  191.             -- TEMPORARY
  192.             -- TEMPORARY
  193.             UI.PageCampaignStart.GUI.MapList:Clear();
  194.             UI.PageCampaignStart.GUI.MapList:ClearColumns();
  195.             UI.PageCampaignStart.GUI.MapList:AddColumn("Level", 80, UIALIGN_LEFT);
  196.             UI.PageCampaignStart.GUI.MapList:AddColumn("Mission", 100, UIALIGN_LEFT);
  197.             for i, Table in DEFIANT do
  198.                 UI.PageCampaignStart.GUI.MapList:AddItem(Table[1], Table[2]);
  199.             end
  200.  
  201.             UI.PageCampaignStart.GUI.Easy.OnChanged = UI.PageCampaignStart.DifficultyChanged;
  202.             UI.PageCampaignStart.GUI.Medium.OnChanged = UI.PageCampaignStart.DifficultyChanged;
  203.             UI.PageCampaignStart.GUI.Hard.OnChanged = UI.PageCampaignStart.DifficultyChanged;
  204.  
  205.             UI.PageCampaignStart.GUI.Easy:SetChecked(0);
  206.             UI.PageCampaignStart.GUI.Medium:SetChecked(0);
  207.             UI.PageCampaignStart.GUI.Hard:SetChecked(0);
  208.  
  209.             UI.PageCampaignStart.iDifficultyLevel = 1;
  210.  
  211.             if getglobal("game_Difficulty") then
  212.                 UI.PageCampaignStart.iDifficultyLevel = getglobal("game_Difficulty");
  213.             end
  214.  
  215.             if (tonumber(UI.PageCampaignStart.iDifficultyLevel) == 0) then
  216.                 UI.PageCampaignStart.GUI.Easy:SetChecked(1);
  217.             elseif (tonumber(UI.PageCampaignStart.iDifficultyLevel) == 1) then
  218.                 UI.PageCampaignStart.GUI.Medium:SetChecked(1);
  219.             else
  220.                 UI.PageCampaignStart.GUI.Hard:SetChecked(1);
  221.             end
  222.             
  223.             if (tonumber(getglobal("ai_autobalance")) ~= 0) then
  224.                 UI.PageCampaignStart.GUI.AutoBalance:SetChecked(1);
  225.             else
  226.                 UI.PageCampaignStart.GUI.AutoBalance:SetChecked(0);
  227.             end            
  228.             
  229.         end
  230.     },
  231.     
  232.     ShowSplashScreen = function()
  233.         UI.SplashScreen(System:LoadImage("textures/controls"), nil, 1, 12, UI.PageCampaignStart.StartGame);
  234.     end,
  235.     
  236.     StartGame = function()
  237.         if (UI.PageCampaignStart.szLevelName) then    
  238.             setglobal("g_GameType", "Default");
  239.             
  240.             UI.PageCampaign:SetAIDifficulty(UI.PageCampaignStart.iDifficultyLevel);
  241.             
  242.             Game:SendMessage("StartLevel "..UI.PageCampaignStart.szLevelName);
  243.         end
  244.         UI.PageCampaignStart.szLevelName = nil;
  245.     end,
  246.     
  247.     DifficultyChanged = function (Sender)
  248.         UI.PageCampaignStart.GUI.Easy:SetChecked(0);
  249.         UI.PageCampaignStart.GUI.Medium:SetChecked(0);
  250.         UI.PageCampaignStart.GUI.Hard:SetChecked(0);
  251.  
  252.         Sender:SetChecked(1);
  253.  
  254.         if (Sender:GetName() == "Easy") then
  255.             UI.PageCampaignStart.iDifficultyLevel = 0;
  256.         elseif (Sender:GetName() == "Medium") then
  257.             UI.PageCampaignStart.iDifficultyLevel = 1;
  258.         else
  259.             UI.PageCampaignStart.iDifficultyLevel = 2;
  260.         end
  261.         
  262.         UI.PageCampaign:SetAIDifficulty(UI.PageCampaignStart.iDifficultyLevel);
  263.     end
  264. }
  265.  
  266. UI.PageCampaignLoad    =
  267. {
  268.     LevelList={},
  269.     CheckpointName = {},
  270.     iDifficultyLevel = 1,
  271.     GUI=
  272.     {    
  273.         CheckpointLabel=
  274.         {
  275.             skin = UI.skins.MenuBorder,
  276.             left = 515, top = 147,
  277.             width = 265, height = 28,
  278.             bordersides = "tlr",
  279.             
  280.             halign = UIALIGN_CENTER,
  281.             
  282.             text = Localize("Checkpoint"),            
  283.         },
  284.  
  285.         CheckpointList=
  286.         {
  287.             skin = UI.skins.ListView,
  288.             left = 515, top = 174,
  289.             width = 265, height = 176,
  290.                         
  291.             fontsize = 12,
  292.             
  293.             zorder = 10,
  294.             
  295.             tabstop = 4,
  296.             
  297.             vscrollbar=
  298.             {
  299.                 skin = UI.skins.VScrollBar,
  300.             },
  301.             hscrollbar=
  302.             {
  303.                 skin = UI.skins.HScrollBar,
  304.             },
  305.             
  306.             OnChanged = function(Sender)
  307.                 UI.PageCampaignLoad:SetPicture();        
  308.             end
  309.         },
  310.  
  311.         LevelLabel=
  312.         {
  313.             skin = UI.skins.MenuBorder,
  314.             left = 205, top = 147,
  315.             width = 300, height = 28,
  316.             
  317.             bordersides = "tlr",
  318.             
  319.             halign = UIALIGN_CENTER,
  320.             
  321.             text = Localize("Level");
  322.         },
  323.  
  324.         LevelList=
  325.         {
  326.             skin = UI.skins.ListView,
  327.             left = 205, top = 174,
  328.             width = 300, height = 244,
  329.             
  330.             tabstop = 3,
  331.             
  332.             zorder = 10,
  333.             
  334.             vscrollbar=
  335.             {
  336.                 skin = UI.skins.VScrollBar,
  337.             },
  338.             
  339.             hscrollbar=
  340.             {
  341.                 skin = UI.skins.HScrollBar,
  342.             },
  343.             
  344.             OnChanged = function(Sender)
  345.                 UI.PageCampaignLoad.PopulateCheckpointList();
  346.             end,
  347.         },
  348.  
  349. --        difficultystatic=
  350. --        {
  351. --            skin = UI.skins.Label,
  352. --            left = 140, top = 365,
  353. --            width = 182, height = 28,
  354.  
  355. --            text = Localize("Difficulty"),
  356. --        },
  357.  
  358. --        difficulty=
  359. --        {
  360. --            skin = UI.skins.ComboBox,
  361. --            left = 325, top = 365,
  362. --            width = 180, height = 28,        
  363.             
  364. --            OnChanged = function(Sender)
  365. --                UI.PageCampaignLoad.iDifficultyLevel = Sender:GetSelectionIndex()-1;
  366. --            end,
  367. --        },
  368.  
  369.         thumbnail=
  370.         {
  371.             skin = UI.skins.MenuBorder,
  372.             left = 583, top = 356,
  373.             width = 128, height = 96,
  374.             
  375.             color = "255 255 255 255",
  376.         },
  377.  
  378.         profilenamestatic=
  379.         {
  380.             skin = UI.skins.Label,
  381.             left = 140, top = 424,
  382.             width = 182, height = 28,
  383.  
  384.             text = Localize("CurrentProfile"),            
  385.         },
  386.  
  387.         profilename=
  388.         {
  389.             skin = UI.skins.MenuStatic,
  390.             halign = UIALIGN_LEFT,
  391.             
  392.             left = 325, top = 424,
  393.             width = 180, height = 28,        
  394.         },
  395.  
  396.         loadgame=
  397.         {
  398.             text=Localize("Load_SaveGame"),
  399.             left = 600,
  400.             skin = UI.skins.BottomMenuButton,
  401.             
  402.             tabstop = 10,
  403.             
  404.             OnCommand=function(Sender)
  405.             
  406.                 local iSelection = UI.PageCampaignLoad.GUI.CheckpointList:GetSelection(0);
  407.  
  408.                 if not iSelection then
  409.                     return
  410.                 end
  411.                 
  412.                 UI.PageCampaignLoad.szFileName = UI.PageCampaignLoad.CheckpointName[iSelection];
  413.                 
  414.                 if (ClientStuff) then
  415.                     UI.YesNoBox(Localize("TerminateCurrentGame"), Localize("TerminateCurrentGameLabel"), UI.PageCampaignLoad.LoadGame);
  416.                 else
  417.                     UI.PageCampaignLoad.LoadGame();
  418.                 end
  419.             end,
  420.         },
  421.         
  422.         OnActivate = function(Sender)
  423.         
  424.             Sender.CheckpointList.OnCommand = Sender.loadgame.OnCommand;
  425.         
  426.             UI.PageCampaignStart.GUI.OnActivate(Sender);
  427.             
  428.             --UI.PageCampaignLoad.iDifficultyLevel = 1;
  429.             
  430.             --if getglobal("game_Difficulty") then
  431.                 --UI.PageCampaignLoad.iDifficultyLevel = getglobal("game_Difficulty");
  432.             --end
  433.  
  434.             Sender.LevelList:Clear();
  435.             Sender.CheckpointList:Clear();
  436.             --Sender.difficulty:Clear();
  437.             --Sender.difficulty:AddItem(Localize("Easy"));
  438.             --Sender.difficulty:AddItem(Localize("Medium"));
  439.             --Sender.difficulty:AddItem(Localize("Hard"));
  440.  
  441.             --Sender.difficulty:SelectIndex(UI.PageCampaignLoad.iDifficultyLevel+1);
  442.  
  443.             Sender.LevelList.OnCommand = Sender.loadgame.OnCommand;        
  444.             Sender.LevelList:Clear();
  445.  
  446.             local szProfileName = getglobal("g_playerprofile");
  447.             
  448.             if ((not szProfileName) or (strlen(szProfileName) < 1)) then
  449.                 szProfileName = "default";
  450.                 g_playerprofile = "default";
  451.             end
  452.             
  453.             Sender.profilename:SetText(szProfileName);
  454.  
  455.             UI.PageCampaignLoad.SaveList = nil;
  456.             UI.PageCampaignLoad.SaveList = Game:GetSaveGameList(szProfileName);
  457.  
  458.             UI.PageCampaignLoad.LevelList = {};
  459.             local LevelList = UI.PageCampaignLoad.LevelList;
  460.                 
  461.             for i, SaveGame in UI.PageCampaignLoad.SaveList do
  462.                 if (not LevelList[SaveGame.Level]) then
  463.                     LevelList[SaveGame.Level] = {};
  464.                 end
  465.                 tinsert(LevelList[SaveGame.Level], SaveGame);
  466.                 
  467.                 -- remove the "n" that lua just inserts (tinsert call)
  468.                 LevelList[SaveGame.Level].n = nil;
  469.             end
  470.                 
  471.             UI.PageCampaignLoad:PopulateLevelList();
  472.             UI.PageCampaignLoad:SetPicture();
  473.         end,
  474.     },
  475.     
  476.     SetPicture = function()
  477.         local iSelection = UI.PageCampaignLoad.GUI.CheckpointList:GetSelection(0);
  478.  
  479.         if iSelection then
  480.         
  481.             local szFileName = UI.PageCampaignLoad.CheckpointName[iSelection];
  482.             
  483.             if (szFileName and strlen(szFileName) > 1) then
  484.             
  485.                 szFileName = "profiles/player/"..getglobal("g_playerprofile").."/savegames/"..szFileName;
  486.             
  487.                 local iTexture = System:LoadImage(szFileName);
  488.     
  489.                 if (iTexture) then
  490.                     UI.PageCampaignLoad.GUI.thumbnail:SetColor("255 255 255 255");
  491.                     UI.PageCampaignLoad.GUI.thumbnail:SetTexture(iTexture);
  492.     
  493.                     return;
  494.                 end
  495.             end
  496.         end
  497.  
  498.         UI.PageCampaignLoad.GUI.thumbnail:SetColor("0 0 0 64");
  499.         UI.PageCampaignLoad.GUI.thumbnail:SetTexture(nil);
  500.     end,
  501.     
  502.     LoadGame = function()
  503.         printf(UI.PageCampaignLoad.szFileName);
  504.         if (UI.PageCampaignLoad.szFileName) then
  505.             --UI.PageCampaign.SetAIDifficulty(UI.PageCampaignLoad.iDifficultyLevel);
  506.     
  507.             setglobal("g_GameType","Default");
  508.             
  509.             Game:SendMessage("LoadGame "..UI.PageCampaignLoad.szFileName);        
  510.         end
  511.  
  512.         UI.PageCampaignLoad.szFileName = nil;
  513.     end,
  514.     
  515.     PopulateLevelList = function()
  516.         local LevelList = UI.PageCampaignLoad.LevelList;
  517.         local ListView = UI.PageCampaignLoad.GUI.LevelList;
  518.         
  519.         ListView:Clear();
  520.         
  521.         -- this is needed so that the levels are in order of appearence
  522.         -- it's not efficient, but it's fast implemented, and no changes needed
  523.         for i, Level in DEFIANT do
  524.             for szLevelName, CheckPointList in LevelList do
  525.                 if (strlower(tostring(szLevelName)) == strlower(tostring(Level[1]))) then
  526.                     ListView:AddItem(FormatName(szLevelName));
  527.                     break;
  528.                 end
  529.             end
  530.         end
  531.     end,
  532.     
  533.     PopulateCheckpointList = function()
  534.         local LevelList = UI.PageCampaignLoad.LevelList;
  535.         local LevelListView = UI.PageCampaignLoad.GUI.LevelList;
  536.         local ListView = UI.PageCampaignLoad.GUI.CheckpointList;
  537.     
  538.         ListView:Clear();
  539.         UI.PageCampaignLoad.CheckpointName = {};
  540.     
  541.         local iSelection = LevelListView:GetSelection(0);
  542.         
  543.         if (iSelection) then
  544.             local CheckpointList = LevelList[strlower(LevelListView:GetItem(iSelection))];
  545.         
  546.             if (CheckpointList) then
  547.     
  548.                 local iCPCount = count(CheckpointList);
  549.     
  550.                 for i=1, iCPCount do
  551.                     -- remove the .sav part
  552.                     local Checkpoint = CheckpointList[i];
  553.                     local szFileName = strsub(Checkpoint.Filename, 1, strlen(Checkpoint.Filename)-strlen(".sav"));    
  554.                     local szCheckpointName;
  555.     
  556.                     if (i == iCPCount) then 
  557.                         szCheckpointName = format("Checkpoint %d %.2d/%.2d/%.2d [%.2d:%.2d] last", i, Checkpoint.Month, Checkpoint.Day, Checkpoint.Year, Checkpoint.Hour, Checkpoint.Minute);
  558.                     else
  559.                         szCheckpointName = format("Checkpoint %d %.2d/%.2d/%.2d [%.2d:%.2d]", i, Checkpoint.Month, Checkpoint.Day, Checkpoint.Year, Checkpoint.Hour, Checkpoint.Minute);
  560.                     end
  561.     
  562.                     UI.PageCampaignLoad.CheckpointName[ListView:InsertItem(0, szCheckpointName)] = szFileName;
  563.                 end
  564.             end
  565.         end
  566.         
  567.         UI.PageCampaignLoad:SetPicture();
  568.         
  569.         --UI.PageCampaignLoad.GUI.CheckpointList:SortEx(UISORT_DESCENDING, 0);
  570.     end
  571. }
  572.  
  573. function UI.PageCampaign:SetAIDifficulty(difficultylevel)
  574.  
  575.     setglobal("game_Difficulty", difficultylevel);
  576.  
  577.     if game_Difficulty==0 then        -- easy
  578.         System:Log("UI.PageCampaign:SetAIDifficulty easy");
  579.         setglobal("game_Accuracy",0.4);
  580.         setglobal("game_Aggression",0.4);
  581.         setglobal("game_Health",0.4);
  582.         setglobal("ai_allow_accuracy_decrease",1);
  583.         setglobal("ai_allow_accuracy_increase",0);
  584.     
  585.     elseif game_Difficulty==1 then    -- medium
  586.         System:Log("UI.PageCampaign:SetAIDifficulty medium");
  587.         setglobal("game_Accuracy",0.7);
  588.         setglobal("game_Aggression",0.7);
  589.         setglobal("game_Health",0.7);
  590.         setglobal("ai_allow_accuracy_decrease",0);
  591.         setglobal("ai_allow_accuracy_increase",1);
  592.     
  593.     elseif game_Difficulty==2 then    -- hard
  594.         System:Log("UI.PageCampaign:SetAIDifficulty hard");
  595.         setglobal("game_Accuracy",1.0);
  596.         setglobal("game_Aggression",1.0);
  597.         setglobal("game_Health",1.0);
  598.         setglobal("ai_allow_accuracy_decrease",1);
  599.         setglobal("ai_allow_accuracy_increase",1);
  600.     end
  601. end
  602.  
  603.  
  604. AddUISideMenu(UI.PageCampaign.GUI,
  605. {
  606.     { "MainMenu", Localize("MainMenu"), "$MainScreen$", 0},
  607.     { "Options", Localize("Options"), "Options", },
  608. });
  609.  
  610. UI:CreateScreenFromTable("CampaignStart",UI.PageCampaignStart.GUI);
  611. UI:CreateScreenFromTable("CampaignLoad",UI.PageCampaignLoad.GUI);
  612. UI:CreateScreenFromTable("Campaign",UI.PageCampaign.GUI);